package org.web3j.crypto;

import java.math.BigInteger;
import java.security.SignatureException;

import org.bouncycastle.util.encoders.Hex;
import org.web3j.crypto.Sign.SignatureData;
import org.web3j.crypto.gm.SM2Signature;

public class SignMain {
	
	  private static final byte[] TEST_MESSAGE = "A test message".getBytes();
	    
	    public static void main(String[] args) throws SignatureException {
	    	
	    	SM2Signature sm2Signature = SampleKeys.KEY_PAIR.sm2Signature(TEST_MESSAGE);
	    	BigInteger recoverFromSignature = Sign.recoverFromSignature(sm2Signature, TEST_MESSAGE);
	    	System.out.println(Hex.toHexString(Sign.getPublicKeyBytes(recoverFromSignature)));
	    	
	    	
	    	byte[] ethereumMessageHash = Sign.getEthereumMessageHash(TEST_MESSAGE);
//	    	 Sign.SignatureData signatureData =
//	                 Sign.signPrefixedMessage(TEST_MESSAGE, SampleKeys.KEY_PAIR);
	    	
	    	SignatureData signatureData = Sign.signMessage(ethereumMessageHash, SampleKeys.KEY_PAIR, false);
	    	
	    	System.out.println(signatureData.getR().length);
	    	System.out.println(signatureData.getS().length);
	    	System.out.println(signatureData.getV().length);
	    	 
	    	 System.out.println(Hex.toHexString(signatureData.getR()));
	    	 System.out.println(Hex.toHexString(signatureData.getS()));
	    	 System.out.println(Hex.toHexString(signatureData.getV()));
	    	 BigInteger signedMessageHashToKey = //
	    			 Sign.signedMessageHashToKey(ethereumMessageHash, signatureData);
	    	 
	    	 System.out.println(Hex.toHexString(Sign.getPublicKeyBytes(signedMessageHashToKey)));
	    	 

//	         
//	         SM2Signature signature = new SM2Signature(null, null, null);
//	         
//	         Sign.recoverFromSignature(null, TEST_MESSAGE);
	         
		}

}
